package com.bite.spring.trans.controller;

import com.bite.spring.trans.service.LogService;
import com.bite.spring.trans.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Slf4j
@RequestMapping("/trans2")
@RestController
public class TransController2 {
    @Autowired
    private UserService userService;

    @Autowired
    private LogService logService;

    @Transactional
    @RequestMapping("/r1")
    public Boolean r1(String userName, String password) {
        log.info("注册用户");

        int r = userService.insert(userName, password);
        log.info("注册了" + r + "个账户");
        int logCount = logService.insert(userName, "registry");
        log.info("登记了" + logCount + "条信息");
        return true;
    }

}
